package com.chat.datea.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.chat.datea.R;
import com.chat.datea.adapter.GuessSingerFragment_RecyclerView_Adapter;
import com.chat.datea.base.BaseFragment;
import com.chat.datea.bean.UserRecSinger;
import com.chat.datea.utils.volley.VolleySingleton;
import com.google.gson.Gson;

import java.util.List;

/**
 * Created by xyb on 15/10/22.
 */
public class GuessSingerMusicFragment extends BaseFragment {
    private List<UserRecSinger.SonglistEntity> songlist;
    private RecyclerView recyclerView;
    private GuessSingerFragment_RecyclerView_Adapter listViewAdapter;
    private VolleySingleton singleton;
    private String songListUrl = null;

    public GuessSingerMusicFragment(String songListUrl) {
        singleton = VolleySingleton.getVolleySingleton(mActivity);
        this.songListUrl = songListUrl;
        Log.e("GuessSingerMusicFragmen", songListUrl);
    }

    @Override
    protected void initData() {

        initListData();

    }

    private void initListData() {
        StringRequest request = new StringRequest(songListUrl, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Gson gson = new Gson();
                UserRecSinger recSinger = gson.fromJson(response, UserRecSinger.class);
                songlist = recSinger.getSonglist();
                listViewAdapter = new GuessSingerFragment_RecyclerView_Adapter(mActivity, songlist);
                recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));

                recyclerView.setAdapter(listViewAdapter);

            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        singleton.addQueue(request, "GuessSingerFragment");

    }

    @Override
    protected void initView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.singer_listView);


    }

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container) {
        view = inflater.inflate(R.layout.singer_recycview, null);
        return view;
    }

}
